/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.easyseata.tc.coordinator;

import com.easyseata.core.exception.TransactionException;
import com.easyseata.core.model.BranchStatus;
import com.easyseata.core.model.BranchType;
import com.easyseata.core.model.GlobalStatus;
import com.easyseata.tc.session.BranchSession;
import com.easyseata.tc.session.GlobalSession;

/**
 * The interface Core.
 *
 */
public interface Core {

	Long branchRegister(BranchType branchType, String resourceId, String clientId, String xid, String applicationData,
			String lockKeys) throws TransactionException;

	
    /**
     * Begin a new global transaction.
     *
     * @param applicationId           ID of the application who begins this transaction.
     * @param transactionServiceGroup ID of the transaction service group.
     * @param name                    Give a name to the global transaction.
     * @param timeout                 Timeout of the global transaction.
     * @return XID of the global transaction
     * @throws TransactionException Any exception that fails this will be wrapped with TransactionException and thrown
     * out.
     */
    String begin(String applicationId, String transactionServiceGroup, String name, int timeout)
        throws TransactionException;


	void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData)
			throws TransactionException;


	boolean lockQuery(BranchType branchType, String resourceId, String xid, String lockKeys)
			throws TransactionException;


	BranchStatus branchCommit(GlobalSession globalSession, BranchSession branchSession) throws TransactionException;


	BranchStatus branchRollback(GlobalSession globalSession, BranchSession branchSession) throws TransactionException;


	boolean doGlobalCommit(GlobalSession globalSession, boolean retrying) throws TransactionException;


	GlobalStatus commit(String xid) throws TransactionException;


	GlobalStatus rollback(String xid) throws TransactionException;


	boolean doGlobalRollback(GlobalSession globalSession, boolean retrying) throws TransactionException;
  

}
